﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewRen.Models.ViewModel
{
    public class vProductList
    {
        public int ID { get; set; }


        public string ProductName { get; set; }


        public string Description { get; set; }


        public decimal Price { get; set; }

        public int Integration { get; set; }


        public DateTime Time { get; set; }


        public DateTime Begin { get; set; }

        public DateTime End { get; set; }

        public int BusinessID { get; set; }

        public string BusinessName { set; get; }


        public string Cover { set; get; }

        public vProductList() { }

        public vProductList(Product model)
        {
            DB db = new DB();
            Images image = db.Images.Where(c => c.TID == model.ID && c.ImageType == ImageType.Product).FirstOrDefault();
            this.ID = model.ID;
            this.ProductName = model.ProductName;
            this.Description = model.Description;
            this.Price = model.Price;
            this.Integration = model.Integration;
            this.Time = model.Time;
            this.Begin = model.Begin;
            this.End = model.End;
            this.BusinessID = model.BusinessID;
            this.BusinessName = db.Businesses.Find(model.BusinessID).BusinessName;
            this.Cover = (image==null)?"/Images/userphoto.png":image.Path;
        }
    }
}
